package com.cognizant.app.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cognizant.app.R;
import com.cognizant.app.interf.OnItemClickListener;

import java.util.List;

import butterknife.OnClick;
import butterknife.OnItemClick;

public class LanguageSelectAdapter extends RecyclerView.Adapter<LanguageSelectAdapter.MyViewHolder> {
    private Context context;
    private List<String> list;
    private OnItemClickListener mClickListener;

    public LanguageSelectAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    public void update(List<String> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mClickListener = listener;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.language_recyler_list, parent, false),mClickListener);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Log.i("maolikui", "position:" + position);
        holder.textView.setText(list.get(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        TextView textView;
        private OnItemClickListener mListener;

        public MyViewHolder(View itemView,OnItemClickListener listener) {
            super(itemView);
            mListener = listener;
            itemView.setOnClickListener(this);
            textView = itemView.findViewById(R.id.language_text);
        }

        @Override
        public void onClick(View v) {
            mListener.onItemClick(v,getLayoutPosition());
        }
    }
}
